package com.android.common.mvp.view.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import com.android.common.constant.Constant;
import com.android.common.mvp.view.ActResultCallback;
import java.util.HashMap;
import java.util.Map;

public class ResultEventDispatcherFragment extends Fragment {
    public static final String TAG = "on_act_result_event_dispatcher";

    private Map<Integer, ActResultCallback> mCallbacks = new HashMap<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void startForResult(Intent intent, ActResultCallback callback) {
        mCallbacks.put(Constant.REQUEST_RECORD_SCREEN, callback);
        startActivityForResult(intent, Constant.REQUEST_RECORD_SCREEN);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        ActResultCallback callback = mCallbacks.get(Constant.REQUEST_RECORD_SCREEN);
        mCallbacks.remove(Constant.REQUEST_RECORD_SCREEN);

        if (callback != null) {
            callback.onActivityResult(resultCode, data);
        }
    }
}
